package com.ruoyi.web.controller.face.socketServer;

import com.google.gson.Gson;
import com.ruoyi.tongban.androidapi.util.AndroidBeanUtils;
import com.ruoyi.tongban.facedetect.domain.*;
import com.ruoyi.tongban.facedetect.utils.SessionCacheBody;
import org.yeauty.pojo.Session;

import java.util.Date;

/**
 * @Description
 * @Author caiyanshan
 * @Date 2021/4/13 13:50
 * @Param
 * @Return
 */
public class MySocketService {
  
  /**
   * @Description 首次连接发送消息
   * @Author caiyanshan
   * @Date 2021/4/13 14:09
   * @Param [json, session]
   * @Return java.lang.String
   */
  public String declare(String json, Session session){
    Gson gson = new Gson();
    DeclareMessage loginMessage = gson.fromJson(json, DeclareMessage.class);
    WebSocketSessionBody webSocketSession = new WebSocketSessionBody();
    webSocketSession.setCreateTime(new Date());
    webSocketSession.setSession(session);
    webSocketSession.setSn(loginMessage.getSn());
    SessionCacheBody.setSession(loginMessage.getSn(), webSocketSession);
    DeclareReturnMessage declareReturnMessage = new DeclareReturnMessage();
    declareReturnMessage.setClient_id(loginMessage.getSn());
    declareReturnMessage.setCmd(loginMessage.getCmd());
    AndroidBeanUtils.getFacePersonService().butchAddPeople(loginMessage.getSn());
    return gson.toJson(declareReturnMessage);
  }
  
  /**
   * @Description 心跳
   * @Author caiyanshan
   * @Date 2021/4/13 14:11
   * @Param []
   * @Return java.lang.String
   */
  public String ping(String json){
    Gson gson = new Gson();
    //Message message = gson.fromJson(json, Message.class);
    MessageBody result = new MessageBody();
    result.setCmd("pong");
    return gson.toJson(result);
  }
  
  public String to_client(String json){
/*    Gson gson = new Gson();
    ToClientReturnMessage message = gson.fromJson(json, ToClientReturnMessage.class);*/
    /*message*/
    return "";
  }
}
